package 剑指offer_leetcode;

/**
 * JZ22链表中倒数最后k个结点
 */
public class 剑指Offer22_链表中倒数第k个节点 {
    public ListNode getKthFromEnd(ListNode head, int k) {
        ListNode fast = head;
        ListNode slow = head;
        while(k-->0){
            if(fast==null)
                return null;
            fast =fast.next;
        }
        while(fast!=null){
            fast = fast.next;
            slow = slow.next;
        }
        return slow;
    }
}
